package com.guigu.pd.oms.controller;

import java.util.Arrays;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guigu.pd.serviceapi.pojo.OrderLocationEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guigu.pd.oms.service.OrderLocationService;
import com.guigu.common.utils.PageUtils;
import com.guigu.common.utils.R;



/**
 * 订单位置信息 
 *
 * @author deyran
 * @email deyran@gmail.com
 * @date 2022-07-19 19:29:39
 */
@RestController
@RequestMapping("oms/orderlocation")
public class OrderLocationController {
    @Autowired
    private OrderLocationService orderLocationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderLocationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		OrderLocationEntity orderLocation = orderLocationService.getById(id);

        return R.ok().put("orderLocation", orderLocation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderLocationEntity orderLocation){
		orderLocationService.save(orderLocation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderLocationEntity orderLocation){
		orderLocationService.updateById(orderLocation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		orderLocationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    //根据订单id 去 、 获取该订单收货网点id
    @GetMapping("/getOrderLocationEntitybyorderId/{id}")
    public OrderLocationEntity getOrderLocationEntitybyorderId(@PathVariable("id") String id){

        LambdaQueryWrapper<OrderLocationEntity> lambdaQueryWrapper = new LambdaQueryWrapper<OrderLocationEntity>();
        lambdaQueryWrapper.eq(OrderLocationEntity::getOrderId,id);
        OrderLocationEntity one = orderLocationService.getOne(lambdaQueryWrapper);
        return one;
    }

}
